from os import name
from django.db import models
from main.utils.models import CoreModel
# Create your models here.

table_prefix =  "sys_"

class User(CoreModel):
    login_name = models.CharField(max_length=20, unique=True)
    user_id = models.IntegerField(unique=True, null=True)
    user_name=models.CharField(max_length=20,)
    email=models.EmailField(max_length=100, null=True)
    password=models.CharField(max_length=50)
    status = models.BooleanField(default=False,choices=((True,'启用'),(False,'禁用')))

    class Meta:
        db_table=table_prefix+'user'



class Role(CoreModel):
    name=models.CharField(max_length=20)
    role_key=models.CharField(max_length=20, null=True, unique=True)
    is_admin=models.BooleanField(default=False)
    description=models.CharField(max_length=100,null=True)

    class Meta:
        db_table=table_prefix+'role'


class UserRole(CoreModel):
    user_id=models.IntegerField(unique=True, null=True)
    role_id=models.IntegerField(unique=True, null=True)
    class Meta:
        db_table=table_prefix+'user_role'


class Menu(CoreModel):
    path = models.CharField(max_length=250, verbose_name="路由地址")
    name = models.CharField(max_length=50, verbose_name="菜单名称")
    component = models.CharField(max_length=250, verbose_name="组件路径", default='Layout')
    title = models.CharField(max_length=50, verbose_name="菜单标题")
    icon = models.CharField(max_length=50,null=True, verbose_name="菜单图标")
    parent_id = models.IntegerField(default=0, verbose_name="父级id")
    is_hidden = models.BooleanField(default=False)
    is_cached = models.BooleanField(default=False)
    order_num = models.IntegerField(default=0, verbose_name="菜单顺序")
    
    class Meta:
        db_table=table_prefix+'menu'

class UserMenu(CoreModel):
    user_id=models.IntegerField(unique=True, null=True)
    menu_id=models.IntegerField(unique=True, null=True)
    class Meta:
        db_table=table_prefix+'user_menu'

class RoleMenu(CoreModel):
    role_id=models.IntegerField(unique=True, null=True)
    menu_id=models.IntegerField(unique=True, null=True)
    class Meta:
        db_table=table_prefix+'role_menu'

